-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added UTs for GetAllTribes, GetTotalTribes & GetListedTribes #1555
Conversation
rctx := chi.NewRouteContext() | ||
tagVals := pq.StringArray{"tag1", "tag4", "tag7"} | ||
tags := strings.Join(tagVals, ",") | ||
rctx.URLParams.Add("tags", tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tags should be in URL query not Params
rctx := chi.NewRouteContext() | ||
tagVals := pq.StringArray{} | ||
tags := strings.Join(tagVals, ",") | ||
rctx.URLParams.Add("tags", tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tags should be in URLQuery, not URLParams
@@ -10,12 +10,13 @@ func TribeRoutes() chi.Router { | |||
r := chi.NewRouter() | |||
tribeHandlers := handlers.NewTribeHandler(db.DB) | |||
r.Group(func(r chi.Router) { | |||
r.Get("/", handlers.GetListedTribes) | |||
r.Get("/{tags}", tribeHandlers.GetListedTribes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change the URL and add tags params to it, the tags come come the URL query.
This reverts commit 9c0ca29.
Created another pull request to fix this.
…On Fri, Feb 23, 2024 at 3:43 PM Raphael Osaze Eyerin < ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In handlers/tribes_test.go
<#1555 (comment)>
:
> +func TestGetListedTribes(t *testing.T) {
+ mockDb := mocks.NewDatabase(t)
+ tHandler := NewTribeHandler(mockDb)
+
+ t.Run("should only return tribes associated with a passed tag query", func(t *testing.T) {
+ rr := httptest.NewRecorder()
+ handler := http.HandlerFunc(tHandler.GetListedTribes)
+ expectedTribes := []db.Tribe{
+ {UUID: "1", Name: "Tribe 1", Tags: pq.StringArray{"tag1", "tag2", "tag3"}},
+ {UUID: "2", Name: "Tribe 2", Tags: pq.StringArray{"tag4", "tag5"}},
+ {UUID: "3", Name: "Tribe 3", Tags: pq.StringArray{"tag6", "tag7", "tag8"}},
+ }
+ rctx := chi.NewRouteContext()
+ tagVals := pq.StringArray{"tag1", "tag4", "tag7"}
+ tags := strings.Join(tagVals, ",")
+ rctx.URLParams.Add("tags", tags)
The tags should be in URL query not Params
------------------------------
In handlers/tribes_test.go
<#1555 (comment)>
:
> + assert.EqualValues(t, expectedTribes, returnedTribes)
+
+ })
+
+ t.Run("should return all tribes when no tag queries are passed", func(t *testing.T) {
+ rr := httptest.NewRecorder()
+ handler := http.HandlerFunc(tHandler.GetListedTribes)
+ expectedTribes := []db.Tribe{
+ {UUID: "1", Name: "Tribe 1", Tags: pq.StringArray{"tag1", "tag2", "tag3"}},
+ {UUID: "2", Name: "Tribe 2", Tags: pq.StringArray{"tag4", "tag5"}},
+ {UUID: "3", Name: "Tribe 3", Tags: pq.StringArray{"tag6", "tag7", "tag8"}},
+ }
+ rctx := chi.NewRouteContext()
+ tagVals := pq.StringArray{}
+ tags := strings.Join(tagVals, ",")
+ rctx.URLParams.Add("tags", tags)
The tags should be in URLQuery, not URLParams
------------------------------
In routes/tribes.go
<#1555 (comment)>
:
> @@ -10,12 +10,13 @@ func TribeRoutes() chi.Router {
r := chi.NewRouter()
tribeHandlers := handlers.NewTribeHandler(db.DB)
r.Group(func(r chi.Router) {
- r.Get("/", handlers.GetListedTribes)
+ r.Get("/{tags}", tribeHandlers.GetListedTribes)
Why change the URL and add tags params to it, the tags come come the URL
query.
—
Reply to this email directly, view it on GitHub
<#1555 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN7TITLIR3CW7KLB6RCCCLDYVCFGRAVCNFSM6AAAAABDVZGHCOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQOJYGAYTSNRYG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Describe your changes
Issue ticket number and link
Issue number 1527
#1527
Type of change
Added test to tribes.go for
GetAllTribes
,GetListedTribes
,GetTotalTribes
Please delete options that are not relevant.
Checklist before requesting a review